﻿using ESRI.ArcGIS.Client;
using QDP.Platform.ObjService;
using Services.Maps;

namespace Apps.Maps
{
    public static class LayerFactory
    {
        public static Layer CreateLayer(ServiceBase entity)
        {
            var layerObject = entity as ServiceLayer;
            switch (layerObject.Type)
            {
                case "TDTTileLyr":
                    return new TDTTileLyr() { ID = entity.Caption };
                case "AMapLayer":
                    return new AMapLayer() { ID = entity.Caption };
                case "BaiduMapImageTileLayer":
                    return new BaiduMapImageTileLayer() { ID = entity.Caption };
                case "BaiduMapPOITileLayer":
                    return new BaiduMapPOITileLayer() { ID = entity.Caption };
                case "BaiduMapVectorTileLayer":
                    return new BaiduMapVectorTileLayer() { ID = entity.Caption };
                case "OpenStreetLayer":
                    return new OpenStreetLayer() { ID = entity.Caption };
                case "ArcGISDynamicMapServiceLayer":
                    return new ArcGISDynamicMapServiceLayer()
                    {
                        Url = layerObject.Url,
                        ID = entity.Caption,
                    };
                case "ArcGISImageServiceLayer":
                    return new ArcGISImageServiceLayer()
                    {
                        Url = layerObject.Url,
                        ID = entity.Caption,
                    };
                case "FeatureLayer":
                    return new FeatureLayer()
                        {
                            Url = layerObject.Url,
                            Mode = FeatureLayer.QueryMode.OnDemand,
                            AutoSave = true,
                            Where = "1=1"
                        };
                default:
                    return new ArcGISTiledMapServiceLayer()
                        {
                            Url = layerObject.Url,
                            ID = entity.Caption,
                        };
            }
        }
    }
}